﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReturnValue
{
    /// <summary>
    /// 响应包装类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ApiResult<T>
    {
        /// <summary>
        /// 响应信息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public StatusCode Code { get; set; }
        /// <summary>
        /// 泛型数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 成功的响应
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult<T> Success(string message, T data)
        {
            return new ApiResult<T> { Code = StatusCode.Success, Message = message, Data = data };
        }
        /// <summary>
        /// 添加成功
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult<T> AddSuccess(string message, T data)
        {
            return Success("添加" + message + "成功", data);

        }
        /// <summary>
        /// 添加失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ApiResult<T> AddFail(string message)
        {
            return Fail("添加" + message + "失败");
        }
        /// <summary>
        /// 错误的响应
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ApiResult<T> Fail(string message)
        {
            return new ApiResult<T> { Code = StatusCode.Fail, Message = message };
        }
    }
}
